
//decl socket base
#include <sys/types.h>
#include <sys/socket.h>

//decl struct sockaddr_un
#include <linux/un.h>

//decl read write
#include <unistd.h>

//decl strcpy
#include <string.h>

#define STDIN 0
#define STDOUT 1
#define MAXBUF 1024

typedef struct sockaddr SOCKADDR;
typedef struct sockaddr_un SOCKADDR_UN;

static char buf[MAXBUF+1];
static char const sun_path[] = "/tmp/test.socket";
static SOCKADDR_UN s_addr_un;
static int sfd; 
static int len;
int main(void) {
	s_addr_un.sun_family = AF_UNIX;
	strcpy(s_addr_un.sun_path, sun_path);
	sfd = socket(AF_UNIX, SOCK_STREAM, 0);
	connect(sfd, (SOCKADDR*)&s_addr_un, sizeof(SOCKADDR_UN));
	len = read(sfd, buf, MAXBUF);
	write(STDOUT, buf, len);
	len = read(STDIN, buf, MAXBUF);
	write(sfd, buf, len);
	len = read(sfd, buf, MAXBUF);
	write(STDOUT, buf, len);
	close(sfd);
	return 0;
}
